home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
awe2-0_1.lha
/
awe2-0.1
/
Src
/
RCS
/
RNG.cc,v
< prev
next >
Wrap
Text File
|
1989-02-20
|
3KB
|
147 lines
head 3.2;
branch ;
access ;
symbols ;
locks grunwald:3.2; strict;
comment @@;
3.2
date 89.02.20.15.37.01; author grunwald; state Exp;
branches ;
next 3.1;
3.1
date 88.12.20.13.49.05; author grunwald; state Exp;
branches ;
next 1.1;
1.1
date 88.09.18.16.42.27; author grunwald; state Exp;
branches ;
next ;
desc
@@
3.2
log
@Start using Gnu library heaps for schedulers
@
text
@#include "RNG.h"
#include <stream.h>
#include "assert.h"
static char initialized = 0;
RNG::RNG()
{
if (!initialized) {
if (sizeof(double) != 2 * sizeof(unsigned long)) {
cerr << "[Random] sizeof(Double) != 2 Sizeof(long)\n";
exit(1);
};
double x = 1.0;
double y = 0.5;
PrivateRNGType t;
//
// The following is a hack that I attribute to
// Andres Nowatzyk at CMU. The intent of the loop
// is to form the smallest number 0 <= x < 1.0,
// which is then used as a mask for two longwords.
// this gives us a fast way way to produce double
// precision numbers from longwords.
//
// I know that this works for IEEE and VAX floating
// point representations.
//
// A further complication is that gnu C will blow
// the following loop, unless compiled with -ffloat-store,
// because it uses extended representations for some of
// of the comparisons. Thus, we have the following hack.
// If we could specify #pragma optimize, we wouldn't need this.
//
#ifndef NOT_IEEE
t.d = 1.5;
if ( t.u[1] == 0 ) { // sun word order?
t.u[0] = 0x3fffffff;
t.u[1] = 0xffffffff;
}
else {
t.u[0] = 0xffffffff; // encore word order?
t.u[1] = 0x3fffffff;
}
#else
do { // find largest fp-number < 2.0
t.d = x;
x += y;
y *= 0.5;
} while (x != t.d && x < 2.0);
#endif
mantissa.d = 1.0;
mantissa.u[0] ^= t.u[0];
mantissa.u[1] ^= t.u[1]; // mantissa is now 1 for each mantissa bit
initialized = 1;
}
}
unsigned long
RNG::asLong()
{
assert2(0,"subClassResponsibility");
return(0);
}
void
RNG::reset()
{
assert2(0,"subClassResponsibility");
}
@
3.1
log
@Steay version
@
text
@d2 1
d5 1
a5 4
//
// The scale constant is 2^-31. It is used to scale a 31 bit
// long to a double.
//
d7 11
a17 2
const double randomDoubleScaleConstant = 4.656612873077392578125e-10;
const float randomFloatScaleConstant = 4.656612873077392578125e-10;
d19 45
a74 8
}
float RNG::asFloat() {
return( (asLong() & 0x7fffffff) * randomFloatScaleConstant);
}
double RNG::asDouble() {
return( (asLong() & 0x7fffffff) * randomDoubleScaleConstant);
@
1.1
log
@Initial revision
@
text
@@